
import { defineStore } from "pinia";

interface IViewEditorState {
	dragResources: any[],
  selectedElement: any
}

type IViewEditorGetters = {
	PageConfig: (x: IViewEditorState) => any
}

type IViewEditorActions = {
	updateDragResources: (resources: any[]) => void
  updateSelectedElement: (element: any) => void
}

const useViewEditorStore = defineStore<string, IViewEditorState, IViewEditorGetters, IViewEditorActions>('viewEditor', {
	state: () => ({
		dragResources: [],
    selectedElement: null
	}),
  getters: {
    PageConfig: (state: IViewEditorState) => state.dragResources.find(i => i.drag.compName === 'ue-page')
  },
	actions: {
		updateDragResources(resources: any[]) {
			this.dragResources = resources
		},
    updateSelectedElement(element: any) {
      this.selectedElement = element
      Object.keys(this.selectedElement.configs).forEach(key => {
        this.selectedElement.configs[key].config.labelPosition = 'top'
      })
    }
	}
})

export default useViewEditorStore